'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
	
	const {
		wxappid,
		likes_ids = [],
		time
	} = event
	
	const collection = db.collection('users')
	let userinfo = await collection.where({
		wxappid: wxappid
	}).get()
	
	console.log('判断以外：' + JSON.stringify(userinfo.data))
	
	if(userinfo.data.length <= 0) {
		await collection.add({
			wxappid: wxappid,
			likes_ids: likes_ids,
			time: time
		})
		userinfo = await collection.where({
			wxappid: wxappid
		}).get()
	}
	
	//返回数据给客户端
	return {
		code: 200,
		message: "数据请求成功",
		data: userinfo.data[0]
	}
};
